<!DOCTYPE html>
<html>
<head>
    <title>设置首页</title>
    <include file='public/head'>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;} 
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>
</head>
<body>
	<!-- layui-tab开始 -->
	<div class="layui-tab " lay-filter="demo-tab" >
		<!-- 顶部导航菜单开始 -->
		<div class="layui-tab-nav" >
			<ul class="layui-tab-title">
				{:getNav('setting','setting/index')};
			</ul>
		</div>	
		<!-- 顶部导航菜单结束 -->

		<!-- 搜索栏结束 -->
	
		<!-- 内容开始 -->
		<div class="layui-card">
			<div class="layui-side layui-bg-black" style=" margin-left:10px;top:80px;bottom: 20px;">
			    <div class="layui-side-scroll">
			        <script type>
						var settingSrc = '';
					</script>
			      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
					<ul class="layui-nav layui-nav-tree"  lay-filter="test">
						<?php $jsq = 0; ?>
						<volist name="list" id="vo" >
							<if condition="$jsq eq 0">
								<?php $selected = true; ?>
								<script type>
									settingSrc = '{$key}';
								</script>
								<else />
								<?php $selected = false; ?>
							</if>
							<?php $jsq ++; ?>
						    <li class="layui-nav-item layui-nav-itemed <?php if($selected) echo ' layui-this '; ?>">
								<a href="javascript:changePage( '{$key}' );">{$vo.title}</a>
						    </li>
						</volist>
					</ul>
					<empty name="$list" >
					    未检索到配置信息
					</empty>
			    </div>
  			</div>
			<div class="layui-body" style="top: 80px;bottom: 20px;">
				<!-- 内容主体区域 -->
				<div class="layui-card">
					<div class="layui-card-header">快捷操作</div>
					<div class="layui-card-body">
						<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="refreshing();" title="刷新" >
							<i class="layui-icon">&#xe669;</i>
						</button>
						<button type="button" class="layui-btn layui-btn-sm" onclick="reloadSetting();">重载配置</button>
						<button type="button" class="layui-btn layui-btn-sm" onclick="updateCache();">更新缓存</button>
					</div>
				</div>
				<div class="layui-card">
					<div class="layui-card-body">
						<iframe src="" id="setting_iframe" style="width: 100%; border:none; ">
						</iframe>
					</div>
				</div>
			</div>
			
		</div>
		<!-- 内容结束 -->
	</div>
	<!-- layui-tab结束-->
	<include file='public/scripts'>

	<script >

	var form = layui.form
		,layer = layui.layer    //弹出层必需
		,layedit = layui.layedit  //富文本必需
		,laydate = layui.laydate  //日期选择必需
		,table = layui.table  //表格必需
		,element = layui.element;  //选项卡	

	var docheight = window.innerHeight;

	$( '#setting_iframe' ).height( docheight - 240 );

	//切换页面
	var changePage = function( id ){
		//loading
		var index = layer.load(1, {
		  shade: [0.8,'#fff'] //0.1透明度的白色背景
		});
		cachePage( id );
		layer.close( index );
	}
	var cachePage = function( name ){
		$( '#setting_iframe' ).attr( 'src' , '{:cmf_plugin_url("Setting://setting/changePage")}?name='+name );
		return false;
	}
	let name = ( settingSrc == undefined ) ? '' : settingSrc ;
	if( name.length != 0 ){
	    changePage( name );
	}

	//重载配置
	var reloadSetting = function(){
		rq( '{:cmf_plugin_url("Setting://setting/updateSetting")}' );
	}
	//更新缓存
	var updateCache = function(){
		
		rq( '{:cmf_plugin_url("Setting://setting/updateCache")}' );
	}

	var rq = function( url ){
		var index;
		$.ajax({
			url:url,
			async:false,
			beforeSend:function(){
				//loading
				index = layer.load(1, {
				  shade: [0.8,'#fff'] //0.1透明度的白色背景
				});
			},
			complete:function(){
				layer.close( index );
			},
			success:function( res ){
				layer.msg( res.message  , { icon:res.code==200?1:5 } , function(){
					window.location.reload();
				});
			},
			error:function(){
				layer.msg( '更新失败' , { icon:5 } );
			}
		});
		
	}

	var refreshing = function(){
		var index = layer.load(1, {
		  shade: [0.8,'#fff'] //0.1透明度的白色背景
		});
		$('#setting_iframe').attr('src', $('#setting_iframe').attr('src'));
		layer.close( index );
	}
	</script>


</body>
</html>